﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CApMFSearchCondition
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections;
using Tecnomatix.Engineering;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.ModularFixture;

internal class CApMFSearchCondition
{
  private string m_objectType;
  private string m_attribute;
  private string m_attributeType;
  private object m_value;
  private string m_operator;
  private Hashtable m_planningObjFields;
  private Hashtable m_internalIdPlanningObjs;
  private ArrayList m_derivedInternalIds;
  private Hashtable m_importedFields;

  internal CApMFSearchCondition(
    string objectType,
    string attribute,
    string attributeType,
    string operatorStr,
    object value)
  {
    this.m_objectType = objectType;
    this.m_attribute = attribute;
    this.m_attributeType = attributeType;
    this.m_operator = operatorStr;
    this.m_value = value;
    this.m_planningObjFields = new Hashtable();
    this.m_internalIdPlanningObjs = new Hashtable();
    this.m_derivedInternalIds = new ArrayList();
    this.m_importedFields = new Hashtable();
  }

  internal bool DoesSatisfyCondition(int internalId)
  {
    bool flag1 = false;
    ITxPlanningObject itxPlanningObject;
    if (this.m_internalIdPlanningObjs.Contains((object) internalId))
    {
      itxPlanningObject = (ITxPlanningObject) this.m_internalIdPlanningObjs[(object) internalId];
    }
    else
    {
      itxPlanningObject = new TxEmsGlobalServicesProvider().GetObjectByInternalId(internalId);
      this.m_internalIdPlanningObjs.Add((object) internalId, (object) itxPlanningObject);
    }
    if (!this.m_derivedInternalIds.Contains((object) internalId))
    {
      if (!itxPlanningObject.IsDerivedFromPlanningType(this.ObjectType))
        return false;
      this.m_derivedInternalIds.Add((object) internalId);
    }
    if (!this.m_planningObjFields.Contains((object) internalId))
      this.m_planningObjFields.Add((object) internalId, (object) new Hashtable());
    object field;
    if (!((Hashtable) this.m_planningObjFields[(object) internalId]).Contains((object) this.m_attribute))
    {
      field = itxPlanningObject.GetField(this.m_attribute);
      ((Hashtable) this.m_planningObjFields[(object) internalId]).Add((object) this.m_attribute, field);
    }
    else
      field = ((Hashtable) this.m_planningObjFields[(object) internalId])[(object) this.m_attribute];
    if (this.m_attributeType == "number")
    {
      int int32_1 = Convert.ToInt32(field);
      int int32_2 = Convert.ToInt32(this.m_value);
      if (this.m_operator == "=")
        flag1 = int32_1 == int32_2;
      else if (this.m_operator == ">")
        flag1 = int32_1 > int32_2;
      else if (this.m_operator == "<")
        flag1 = int32_1 < int32_2;
      else if (this.m_operator == ">=")
        flag1 = int32_1 >= int32_2;
      else if (this.m_operator == "<=")
        flag1 = int32_1 <= int32_2;
    }
    else if (this.m_attributeType == "string")
    {
      string str1 = field.ToString();
      string str2 = this.m_value.ToString();
      if (this.m_operator == "equals")
        flag1 = str1 == str2;
      else if (this.m_operator == "contains")
        flag1 = str1.Contains(str2);
    }
    else if (this.m_attributeType == "date")
    {
      DateTime dateTime1 = Convert.ToDateTime(field);
      DateTime dateTime2 = Convert.ToDateTime(this.m_value);
      bool flag2 = dateTime1.Year == dateTime2.Year && dateTime1.Month == dateTime2.Month && dateTime1.Day == dateTime2.Day;
      if (this.m_operator == "=")
        flag1 = flag2;
      else if (this.m_operator == ">" && !flag2)
        flag1 = dateTime1 > dateTime2;
      else if (this.m_operator == "<" && !flag2)
        flag1 = dateTime1 < dateTime2;
      else if (this.m_operator == ">=")
        flag1 = flag2 || dateTime1 >= dateTime2;
      else if (this.m_operator == "<=")
        flag1 = flag2 || dateTime1 <= dateTime2;
    }
    return flag1;
  }

  internal string ObjectType
  {
    get => this.m_objectType;
    set => this.m_objectType = value;
  }

  internal string Attribute
  {
    get => this.m_attribute;
    set => this.m_attribute = value;
  }

  internal object Value
  {
    get => this.m_value;
    set => this.m_value = value;
  }

  internal string OperatorStr
  {
    get => this.m_operator;
    set => this.m_operator = value;
  }

  internal enum ObjectTypeEnum
  {
    String,
    Number,
    Date,
  }

  internal enum NumberOperator
  {
    Equal,
    More,
    Less,
    EqualMore,
    EqualLess,
  }

  internal enum StringOperator
  {
    Equal,
    Contains,
  }

  internal enum DateOperator
  {
    Equal,
    More,
    Less,
    EqualMore,
    EqualLess,
  }
}
